import { isUrl } from '../utils/utils';

const menuData = [
  // {
  // name: 'Dashboard',
  // icon: 'dashboard',
  // path: 'dashboard',
  // hideInBreadcrumb: true,
  // hideInMenu: true,
  // authority: 'admin',
  // },
  {
    name: '用户管理',
    icon: 'yonghuguanli1',
    path: 'user_manage/:list',
  },
  {
    name: '角色管理',
    icon: 'jiaoseguanli1',
    path: 'role_manage/:list',
  },
  {
    name: '权限管理',
    icon: 'quanxian',
    path: 'permission_manage/:list',
  },
  {
    name: '权限授权',
    icon: 'shouquanchenggong',
    path: 'authorization/:list',
  },
  {
    name: '接入系统',
    icon: 'drxx11',
    path: 'service_sys/:list',
  },
  {
    name: '登录日志',
    icon: 'denglurizhi2',
    path: 'login_log/:list',
  },
  {
    name: 'RememberMe Token',
    icon: 'token',
    path: 'remember_me_token_manage/:list',
    // authority: '[menu]-UserManagement',
  },
  {
    name: 'JWT Token',
    icon: 'key1',
    path: 'jwt_token_manage/:list',
  },
  // {
  //   name: 'OAuth2.0 Token',
  //   icon: 'ico_authority',
  //   path: 'oauth_token_manage/:list',
  // },
  // {
  //   name: 'CAS Token',
  //   icon: 'CAS1',
  //   path: 'cas_token_manage/:list',
  // },
  // TODO 用户详情页面 角色详情页 权限详情页 管理服务系统详情页
];

function formatter(data, parentPath = '/', parentAuthority) {
  return data.map(item => {
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

export const getMenuData = () => formatter(menuData);
